<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>    
    <title>增加</title>
	<%@ include file="/WEB-INF/jsp/include.jsp"%>
	<script type="text/javascript">
		var path = "${path }";
		var params = new Object();
		var ysxm = new Object();
		var url = path + "/system/taxclasscode/save";
		
		var url_initSelect = path + "/system/taxclasscode/getSelectData";
		
		$(function(){
			setAjaxLoading();
		});
		
	//提交
	function submit_Add() {

		if (!validform("ssflbmForm")) {
			return;
		}
		//params.ysxm = parent.ysxm.code;
        $('#taxAbleCode').val(parent.ysxm.code);
        
		$.ajax({
			type : "POST",
			url : url,
			dataType : "json",
			data : $('#ssflbmForm').serialize(),
			async : false,

			success : function callback(data) {
				var analyMsg = data;
				if (analyMsg.code != '0000') {
					//$.messager.alert('友情提醒', analyMsg.msg, 'info', function() {
					//});
					$.alert("add", "error", "税收分类编码");
				} else {
					//$.messager.alert("友情提醒", "添加税收分类编码成功。", "info", function() {
					//	parent.btnQuery();
					//	setTimeout("closeLayer()", 100);//设置延时，防止IE下出现异常
					//});
					$.alert("add", "info", "税收分类编码");
				}
			},
			error : function(data, textstatus) {
				//$.messager.alert('友情提醒', data.responseText, 'info', function() {
				//});
				$.alert("default", "error", data.responseText);
			}
		});
	}
	
	
	function setTitle(jobject){
		jobject.attr("title",jobject.find("option:selected").text());
	}
	
	function openYsxm() {
		parent.layer.open({
			type : 2,
			title : '选择应税项目',
			shadeClose : false,
			shade : 0.6,
			area : [ '800px', '500px' ],
			content : '${path}/system/taxclasscode/toTaxableItems',
			success : function(layero, index) {
				
			},
			end : function callback() {
				$('#taxAbleCodeName').val(parent.ysxm.name);
				ysxm.taxableitemsCode = parent.ysxm.code;
				ysxm.taxRateGeneral = parent.ysxm.taxRateGeneral;
				ysxm.taxRateSimple = parent.ysxm.taxRateSimple;
				var taxRateGeneral = $('#taxRateGeneral');
				var taxRateSimple = $('#taxRateSimple');
				removeOptions();
				initSelectbox(1, taxRateGeneral);
				initSelectbox(2, taxRateSimple);
				$.parser.parse();
			}
		});
	}
	
	function initSelectbox(jsff,selectboxObj){
		ysxm.jsff = jsff;
		$.ajax({
			type:"POST",
			url:url_initSelect,
			dataType:"JSON",
			data:ysxm,
			success:function callback(data){
				if(data.code =="0000"){
					var rows = data.returnObject.rows;
					$.each(rows,function(i,v){
						var opt = $('<option></option>').text(v.taxrateName).val(v.taxrateId);
						selectboxObj.append(opt);
					});
					setTitle(selectboxObj);
					selectboxObj.attr('disabled',false);
				}
			},
			error:function(){
			
			}
		});
	}
	
	function removeOptions() {
		$("#taxRateGeneral option").remove();
		$("#taxRateSimple option").remove();
	}
	
	function checkRepeat(taxClassCode){
		if(taxClassCode == ""){
			return;
		}
		var param = new Object();
		param.taxClassCode = taxClassCode;
		$.ajax({
				type : "POST",
				url :'${path}/system/taxclasscode/returnSingleTax',
				dataType : "json",
				data : param,
				async : false,
				success : function callback(data) {

                        if(data.code=="0001"){
                        }else{
                            //$.messager.alert('友情提醒', "税收分类编码重复", 'info', function() {
                            //});
                            $.alert("disabled", "info", "税收分类编码");
                        }
					
				},
				error:function(){
				
				}
		});
	}
	
	</script>
	
  </head>
 
  <body style="margin:0px; padding:0px;">
	  <%@ include file="/WEB-INF/jsp/loading.jsp"%>
		<div class="easyui-layout" fit="true">
			<div data-options="region:'north',border:false,noheader:true" style="height: 200px;">
				<form id="ssflbmForm" method="post">
					<table class="f_table" cellspacing="1">
						<tr>
							<td align="right" class="s_bg" style="width:113px;">税收分类编码：</td>
							<td align="left" style="width: 150px;">
								<input type="text" id="taxClassCode" name="taxClassCode" style="width: 98%;" onChange="checkRepeat(this.value);" class="easyui-validatebox" data-options="required:true" />
							</td>
							<td align="right" class="s_bg" style="width:113px;">商品名称：</td>
							<td align="left" style="width: 150px;">
								<input type="text" id="productName" name="productName" style="width: 98%;" class="easyui-validatebox" data-options="required:true,tipPosition:'left'" />
							</td>
						</tr>
						<tr>
							<td align="right" class="s_bg" style="width:113px;">应税项目：</td>
							<input type="hidden" id="taxAbleCode" name="taxAbleCode" value="">
							<input type="hidden" id="validMark" name="validMark" value=1>
							<input type="hidden" id="delMark" name="delMark" value=0>
							<td align="left" style="width: 150px;"><input type="text"
								id="taxAbleCodeName" name="taxAbleCodeName" style="width: 118px;"
								class="easyui-validatebox" readonly="readonly"
								data-options="required:true" /> <span id="btn_selhyxx"
								class="searchbox-button" style="height: 20px; margin-top: 5px;"
								onclick="openYsxm()"></span></td>
							<td align="right" class="s_bg" style="width:113px;">一般增值税税率：</td>
							<td align="left" style="width: 150px;">
								<select id="taxRateGeneral" name="taxRateGeneral" class="easyui-validatebox" data-options="required:true,tipPosition:'left'" 
									onChange="setTitle($(this));" style="width: 148px;height:35px" disabled="disabled">
									<option value="">请选择...</option>
								</select>
							</td>
						</tr>
						<tr>
							<td align="right" class="s_bg" style="width:113px;">简易增值税税率：</td>
							<td align="left" style="width: 150px;">
								<select id="taxRateSimple" name="taxRateSimple" class="easyui-validatebox" data-options="required:true" 
									onChange="setTitle($(this));" style="width: 148px;height:35px" disabled="disabled">
									<option value="">请选择...</option>
								</select>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div data-options="region:'south',border:false,noheader:true" align="center" style="height: 35px;margin-top: 2px;">
				<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="submit_Add();">确定</a> 
				<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="closeLayer();">取消</a>
			</div>
		</div>
  </body>
</html>
